package cei 
{
	import com.google.maps.CopyrightCollection;
	import com.google.maps.TileLayerBase;
	
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.events.IOErrorEvent;
	import flash.geom.Point;
	import flash.net.URLRequest;
	
	public class GeoServTileLayer extends TileLayerBase 
	{
	   	private var _layerName:String;
	   	private var _servStr:String;
		
	  	public function GeoServTileLayer(alpha:Number, layerName:String, servStr:String) 
		{
	  		var copyCollection:CopyrightCollection = new CopyrightCollection();
	    	super(copyCollection,0,14,alpha);
	    	this._layerName = layerName;
	    	this._servStr = servStr;
	  	}
	
		/**
	   	* Creates and loads a tile (x, y) at the given zoom level.
	   	* @param tilePos  Tile coordinates.
	   	* @param zoom  Tile zoom.
	   	* @return  Display object representing the tile.
	   	*/
	  	public override function loadTile(tilePos:Point, zoom:Number):DisplayObject 
		{
	  		var tileLoader:Loader = new Loader();
	    	var urlRequest:URLRequest = new URLRequest(_servStr + "geoserver/gwc/service/gmaps?layers=" + _layerName + "&zoom=" + zoom + "&x=" + tilePos.x + "&y=" + tilePos.y);
	    	//tileLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
	    	tileLoader.load(urlRequest);
			
	    	return tileLoader;
	  	}
	  	private function ioErrorHandler(event:IOErrorEvent):void 
		{
	    	//trace("ioErrorHandler: " + event);
	  	}
	}
}

